package si.unimb.src.wifisms.control;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ConnectivityReceiver extends BroadcastReceiver {

	final static protected Object lockObject = new Object();

	@Override
	public void onReceive(Context context, Intent intent) {

		if(intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {

			Log.d("HelloWS2", "onReceive: CONNECTIVITY_ACTION");
	    	generateConnectivityAction();
	    	
	    }
	    
	}

	public static void waitForConnectivityAction() {
	
		synchronized(lockObject) {

			try {
				
				lockObject.wait();
				
			} catch (InterruptedException e) {}
		
		}
		
	}
	
	public static void generateConnectivityAction() {
	
		synchronized(lockObject) {
			
			lockObject.notifyAll();
		
		}
		
	}

}
